/* 
 * Copyright (C), 2016-2020, 厦门盈欣宝金融信息服务有限公司
 * Project Name :boot-parent
 * File Name: org.easytouseit.rabbitmq.config
 * Encoding UTF-8 
 * Version: 1.0 
 * Date: 2018-09-14 16:19
 * History:  
 * 1. Date: 2018-09-14
 *    Author: guojm 
 *    Modification: 新建
 * 2. ...
 */
package org.easytouseit.rabbitmq.direct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.support.RetryTemplate;

import javax.annotation.Resource;

/**
 * @author guojm
 * @version V1.0
 * @date 2018-09-14 下午 16:19
 */
@Configuration
public class DirectRabbitMQConfig {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public final static String QUEUE_NAME = "direct-queue";
    public final static String EXCHANGE_NAME = "direct-exchange";
    public final static String ROUTING_KEY = "spring-boot-key";

    // 创建队列
    @Bean("queueDirect")
    public Queue queueDirect() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }
    // 创建一个 topic 类型的交换器
    @Bean("exchangeDirect")
    public DirectExchange exchangeDirect() {
        return new DirectExchange(EXCHANGE_NAME,true,false);
    }

    // 使用路由键（routingKey）把队列（Queue）绑定到交换器（Exchange）
    @Bean
    public Binding binding(@Qualifier("queueDirect") Queue queueDirect,
                           @Qualifier("exchangeDirect") DirectExchange exchangeDirect) {
        return BindingBuilder.bind(queueDirect).to(exchangeDirect).with(ROUTING_KEY);
    }

}
